//
//  MSBuidingBankCardController.m
//  觅尚
//
//  Created by No.8 on 2019/4/20.
//  Copyright © 2019 No.8. All rights reserved.
//

#import "MSBuidingBankCardController.h"

@interface MSBuidingBankCardController ()
{
    CustomNavigationBar *naviagtionBar;
}

/** 姓名*/
@property(nonatomic,strong)UITextField *NameField;

/** 卡号*/
@property(nonatomic,strong)UITextField *BankNumberField;


/** 银行*/
@property(nonatomic,strong)UITextField *BankCardField;


/** 开户行*/
@property(nonatomic,strong)UITextField *OpeningBankField;

@end

@implementation MSBuidingBankCardController
- (int)navBarBottom {
    if ([WRNavigationBar isIphoneX]) {
        return 88;
    } else {
        return 64;
    }
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];
    self.navigationController.navigationBar.hidden = YES;
    
    
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:YES];
    self.navigationController.navigationBar.hidden = YES;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self CreateNavigationBar];
    
    [self CreatView];
    
    
}
- (void)CreatView{
    /** 提示*/
    UILabel * showTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(30 * px, [self navBarBottom] + 30 * px, ScreenWidth * 0.5, 60 * px)];
    showTitleLabel.textColor = [UIColor grayColor];
    showTitleLabel.text = @"请绑定持卡人本人的银行卡";
    showTitleLabel.textAlignment = NSTextAlignmentLeft;
    showTitleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [self.view addSubview:showTitleLabel];
    
    
    UIView * buidingView = [[UIView alloc] initWithFrame:CGRectMake(showTitleLabel.x, CGRectGetMaxY(showTitleLabel.frame) + 30 * px, ScreenWidth - 60 * px, 600 * px)];
    buidingView.layer.borderColor = BackViewColor.CGColor;
    buidingView.layer.cornerRadius = 30 * px;
    buidingView.layer.masksToBounds = YES;
    //给图层添加一个有色边框
    buidingView.layer.borderWidth = 1;
    [self.view addSubview:buidingView];
    
    
    
    /** 姓名*/
    UILabel * BankNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(30 * px, 45 * px, 250 * px, 60 * px)];
    BankNameLabel.textColor = [UIColor grayColor];
    BankNameLabel.text = @"持卡人姓名";
    BankNameLabel.textAlignment = NSTextAlignmentLeft;
    BankNameLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [buidingView addSubview:BankNameLabel];
    
    
    
    /** 姓名*/
    UITextField * BankNameField = [[UITextField alloc] initWithFrame:CGRectMake(buidingView.width / 2, BankNameLabel.y, buidingView.width / 2 - 60 * px, BankNameLabel.height)];
    BankNameField.textColor = [UIColor whiteColor];
    BankNameField.placeholder = @"请输入持卡人姓名";
    BankNameField.textAlignment = NSTextAlignmentRight;
    [BankNameField setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
    BankNameField.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [buidingView addSubview:BankNameField];
    self.NameField = BankNameField;
    
    
    UIView * NameViewline = [[UIView alloc] initWithFrame:CGRectMake(BankNameLabel.x, buidingView.height / 4, buidingView.width - 60 * px, 1)];
    NameViewline.backgroundColor = [UIColor grayColor];
    [buidingView addSubview:NameViewline];
    
    
    
    /** 卡号*/
    UILabel * BankNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(BankNameLabel.x, CGRectGetMaxY(NameViewline.frame) + 45 * px, BankNameLabel.width, BankNameLabel.height)];
    BankNumberLabel.textColor = [UIColor grayColor];
    BankNumberLabel.text = @"银行卡号";
    BankNumberLabel.textAlignment = NSTextAlignmentLeft;
    BankNumberLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [buidingView addSubview:BankNumberLabel];
    
    
    
    /** 姓名*/
    UITextField * BankNumberField = [[UITextField alloc] initWithFrame:CGRectMake(BankNameField.x, BankNumberLabel.y, BankNameField.width, BankNameField.height)];
    BankNumberField.textColor = [UIColor whiteColor];
    BankNumberField.placeholder = @"请输入银行卡号";
    BankNumberField.textAlignment = NSTextAlignmentRight;
    BankNumberField.keyboardType = UIKeyboardTypeNumberPad;
    [BankNumberField setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
    BankNumberField.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [buidingView addSubview:BankNumberField];
    self.BankNumberField = BankNumberField;
    
    
    
    UIView * BankNumberline = [[UIView alloc] initWithFrame:CGRectMake(BankNameLabel.x, buidingView.height / 2, NameViewline.width, NameViewline.height)];
    BankNumberline.backgroundColor = [UIColor grayColor];
    [buidingView addSubview:BankNumberline];
    
    
    
    /** 卡号*/
    UILabel * BankCardLabel = [[UILabel alloc] initWithFrame:CGRectMake(BankNameLabel.x, CGRectGetMaxY(BankNumberline.frame) + 45 * px, BankNameLabel.width, BankNameLabel.height)];
    BankCardLabel.textColor = [UIColor grayColor];
    BankCardLabel.text = @"银行";
    BankCardLabel.textAlignment = NSTextAlignmentLeft;
    BankCardLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [buidingView addSubview:BankCardLabel];
    
    
    
    /** 姓名*/
    UITextField * BankCardField = [[UITextField alloc] initWithFrame:CGRectMake(BankNameField.x, BankCardLabel.y, BankNameField.width, BankNameField.height)];
    BankCardField.textColor = [UIColor whiteColor];
    BankCardField.placeholder = @"请输入银行";
    BankCardField.textAlignment = NSTextAlignmentRight;
    [BankCardField setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
    BankCardField.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [buidingView addSubview:BankCardField];
    self.BankCardField = BankCardField;
    
    
    
    UIView * BankCardline = [[UIView alloc] initWithFrame:CGRectMake(BankNameLabel.x, buidingView.height / 4 * 3, NameViewline.width, NameViewline.height)];
    BankCardline.backgroundColor = [UIColor grayColor];
    [buidingView addSubview:BankCardline];
    
    
    
    /** 具体开户行*/
    UILabel * OpeningBankLabel = [[UILabel alloc] initWithFrame:CGRectMake(BankNameLabel.x, CGRectGetMaxY(BankCardline.frame) + 45 * px, BankNameLabel.width, BankNameLabel.height)];
    OpeningBankLabel.textColor = [UIColor grayColor];
    OpeningBankLabel.text = @"具体开户行";
    OpeningBankLabel.textAlignment = NSTextAlignmentLeft;
    OpeningBankLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [buidingView addSubview:OpeningBankLabel];
    
    
    
    /** 姓名*/
    UITextField * OpeningBankField = [[UITextField alloc] initWithFrame:CGRectMake(BankNameField.x, OpeningBankLabel.y, BankNameField.width, BankNameField.height)];
    OpeningBankField.textColor = [UIColor whiteColor];
    OpeningBankField.placeholder = @"请输入开户行";
    OpeningBankField.textAlignment = NSTextAlignmentRight;
    [OpeningBankField setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
    OpeningBankField.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [buidingView addSubview:OpeningBankField];
    self.OpeningBankField = OpeningBankField;
    
    
    /** 按钮*/
    UIButton * DetermineButton = [[UIButton alloc] initWithFrame:CGRectMake(80 * px, CGRectGetMaxY(buidingView.frame) + 80 * px, ScreenWidth - 160 * px, 120 * px)];
    [DetermineButton setTitle:@"确定" forState:UIControlStateNormal];
    DetermineButton.layer.cornerRadius = 60 * px;
    DetermineButton.layer.masksToBounds = YES;
    [DetermineButton setBackgroundImage:[UIImage imageNamed:@"底部按钮背景"] forState:UIControlStateNormal];
    DetermineButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [DetermineButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [DetermineButton addTarget:self action:@selector(DetermineButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:DetermineButton];
    
    
    
}

- (void)DetermineButtonClick{
     [MBManager showLoading];
    if (self.NameField.text.length == 0 || self.BankNumberField.text.length == 0 || self.BankCardField.text.length == 0 || self.OpeningBankField.text.length == 0) {
        [MBManager showBriefAlert:@"银行信息不能为空"];
        [MBManager hideAlert];
        return;
    }
    NSDictionary * params = @{@"uid":[WYCAccountTool unarchiveuid],@"userName":self.NameField.text,@"cardNumber":self.BankNumberField.text,@"bankName":self.BankCardField.text,@"bankCode":self.OpeningBankField.text};
    [HTTPRequest POST:MSaddBankcard params:params succeed:^(id responseObject) {
        if (CodeStr) {
            [MBManager hideAlert];
            [MBManager showBriefAlert:responseObject[@"msg"]];
        }else{
             [MBManager hideAlert];
            [MBManager showBriefAlert:responseObject[@"msg"]];
            
        }
    } failure:^(NSError *error) {
        [MBManager hideAlert];
        [MBManager showBriefAlert:Failed];
    }];
    
    
    
}
- (void)CreateNavigationBar{
    
    self.view.backgroundColor = backgroundcolor;
    naviagtionBar = [[CustomNavigationBar alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, [self navBarBottom])];
    [self.view addSubview:naviagtionBar];
    naviagtionBar.titleLabel.text = @"提现";
    naviagtionBar.rightBtn.hidden = YES;
    naviagtionBar.rightBtnTitle.hidden = YES;
    [self.view addSubview:naviagtionBar];
    
    [naviagtionBar.leftBtn setImage:[UIImage imageNamed:@"左箭头"] forState:UIControlStateNormal];
    [naviagtionBar.leftBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    
}
- (void)backClick{
    
    [self.navigationController popViewControllerAnimated:NO];
}

@end
